import urllib.request
url = 'https://www.ip.cn/'

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36'
}

request = urllib.request.Request(url=url, headers=headers)

# response = urllib.request.urlopen(request)

proxies = {
    'http': '101.37.26.136:80'
}

# 1.获取 handler 对象    handler  build_opener  open
handler = urllib.request.ProxyHandler(proxies=proxies)

# 2.获取build_opener对象
opener = urllib.request.build_opener(handler)

# 调用 open 方法
response = opener.open(request)

decode = response.read().decode('utf-8')

print(decode)

with open('ip.html', 'w', encoding='utf-8') as f:
    f.write(decode)
